package cn.com.yusys.yusp.mobile.web.rest;

import cn.com.yusys.yusp.admin.Utils.IDUtils;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import cn.com.yusys.yusp.mobile.service.CustomerService;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/mobile/customer")
public class CustomerResource {

    @Resource
    CustomerService customerService;

    @GetMapping("/getCustomerLeader")
    public ResultDto<Object> getCustomerLeader(QueryModel queryModel) {
        return new ResultDto<>(customerService.getCustomerLeader(queryModel));
    }

    @GetMapping("/getCustInfo")
    public ResultDto<Object> getCustInfo(QueryModel queryModel) {
        return new ResultDto<>(customerService.getCustInfo(queryModel));
    }

    @GetMapping("/getMerchantInfo")
    public ResultDto<Object> getMerchantInfo(QueryModel queryModel) {
        return new ResultDto<>(customerService.getMerchantInfo(queryModel));
    }

    @GetMapping("/getExpirationReminder")
    public ResultDto<Object> getExpirationReminder(QueryModel queryModel) {
        return new ResultDto<>(customerService.getExpirationReminder(queryModel));
    }

    @GetMapping("/getLargeAmount")
    public ResultDto<Object> getLargeAmount(QueryModel queryModel) {
        return new ResultDto<>(customerService.getLargeAmount(queryModel));
    }

    @GetMapping("/getCustomerOverdue")
    public ResultDto<Object> getCustomerOverdue(QueryModel queryModel) {
        return new ResultDto<>(customerService.getCustomerOverdue(queryModel));
    }

    @GetMapping("/getWithdrawalInAdvance")
    public ResultDto<Object> getWithdrawalInAdvance(QueryModel queryModel) {
        return new ResultDto<>(customerService.getWithdrawalInAdvance(queryModel));
    }

    @GetMapping("/getBirthdayCustomerReminder")
    public ResultDto<Object> getBirthdayCustomerReminder(QueryModel queryModel) {
        return new ResultDto<>(customerService.getBirthdayCustomerReminder(queryModel));
    }

    @GetMapping("/getImportantCustomerReminder")
    public ResultDto<Object> getImportantCustomerReminder(QueryModel queryModel) {
        return new ResultDto<>(customerService.getImportantCustomerReminder(queryModel));
    }

    @GetMapping("/getWealthCustomerReminder")
    public ResultDto<Object> getWealthCustomerReminder(QueryModel queryModel) {
        return new ResultDto<>(customerService.getWealthCustomerReminder(queryModel));
    }

    @GetMapping("/getRepaymentDueReminder")
    public ResultDto<Object> getRepaymentDueReminder(QueryModel queryModel) {
        return new ResultDto<>(customerService.getRepaymentDueReminder(queryModel));
    }

    @PostMapping("/updateCustomerBasicInformationEditing")
    public ResultDto<Integer> updateCustomerBasicInformationEditing(@RequestBody Map map) {
        return new ResultDto<>(customerService.updateCustomerBasicInformationEditing(map));
    }

    @PostMapping("/insertRecordAddInterview")
    public ResultDto<Integer> insertRecordAddInterview(@RequestBody Map map) {
        map.put("connid", IDUtils.getGuid());
        map.put("calluuid", IDUtils.getGuid());
        return new ResultDto<>(customerService.insertRecordAddInterview(map));
    }

    @PostMapping("/updateCustomerContactInformationEditing")
    public ResultDto<Integer> updateCustomerContactInformationEditing(@RequestBody Map map) {
        return new ResultDto<>(customerService.updateCustomerContactInformationEditing(map));
    }

    @PostMapping("/addCustomerActivity")
    public ResultDto<Integer> addCustomerActivity(@RequestBody Map map) {
        Map<String, Object> customerInfo =  customerService.getCustomerInfo(map);
        //如果customerInfo有值就插入新表中
            if (customerInfo!=null){
                customerInfo.put("activityNo",map.get("activityNo"));
                customerInfo.put("isDocument","0");
                customerInfo.put("isSign","1");
                return new ResultDto<>(customerService.addCustomerActivityInfo(customerInfo));
            }
            //如果没有值就插入customer表中，再插入进活动表
            else {
                map.put("isDocument","1");
                map.put("isSign","1");
                map.put("custNo",IDUtils.getGuid());
                return new ResultDto<>(customerService.addCustomerInfo(map));
            }
    }

}
